{extend name="index-layout" /} {block name="pagecss"}
<link rel="stylesheet" href="__STATIC__/index/css/style_tr.css" />
<link rel="stylesheet" href="__STATIC__/index/css/register.css" />
{/block} {block name="content"}
<div class="banner" style="height:60px;">
  <div class="wrapper">
    <h2 class="wow fadeInUp" style="padding-top:5px;">接口测试</h2>
  </div>
</div>
<div class="login1">
  <div class="login-wp" style="vertical-align:top;padding:60px 50px 25px 50px;position:relative;">
    <a style="position:absolute;top:10px;right:10px;font-size:2em;font-weight:bold;"
      href="{:url('index/Test/Index')}">返回</a>
    <div class="login-hd">
      <h2>{$code.name}</h2>
    </div>
    <div class="login-bd">
      <div class="account-main c-center">
        <div>
          <div class="account-input-cont c-relative">
            <label style="font-size:20px;">商户编号：</label>
            <input id="txtUID" type="number" placeholder="请输入商户编号" autocomplete="off" class="account-input"
              style="width:60%;" value="100001" />
          </div>
          <div class="account-input-cont c-relative">
            <label style="font-size:20px;">支付金额：</label>
            <input id="txtAmount" type="number" placeholder="请输入支付金额" autocomplete="off" class="account-input"
              style="width:60%;" step="0.01" value="0.01" />
          </div>
        </div>
        <div class="login-btn">
          <input id="btnSubmit" type="button" class="btn" value="提交申请付款" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="1毛" onclick="submitOrder(0.1)" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="1元" onclick="submitOrder(1)" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="10元" onclick="submitOrder(10)" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="20元" onclick="submitOrder(20)" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="50元" onclick="submitOrder(50)" />
        </div>

        <div class="login-btn">
          <input type="button" class="btn" value="100元" onclick="submitOrder(100)" />
        </div>
      </div>
    </div>
  </div>
  <br />
  <div class="login-wp" style="vertical-align:top;padding:0px;margin-top:15px;">
    <div id="divResult" style="width:100%;display:flex;align-items:center;justify-content:center;"></div>
  </div>
</div>
{/block} {block name="pagejs"}
<script type="text/javascript">
  var blockIndex = 0
  $.ajaxSetup({
    beforeSend: function () {
      blockIndex = layer.load(1, { shade: 0.6 })
    },
    error: function (xhr, status, error) {
      layer.msg(error, { icon: 2, closeBtn: 0, shade: 0.6 })
    },
    complete: function () {
      layer.close(blockIndex)
    }
  })

  layui.use('layer', function () {
    $('#btnSubmit').click(function () {
      submitOrder()
    })
  })


  function submitOrder(amount) {
    var $ = layui.$
    var txtUID = $('#txtUID')
    var txtAmount = $('#txtAmount')
    var uId = parseInt(txtUID.val())

    if (amount == undefined) {
      var amount = parseFloat(txtAmount.val()).toFixed(2)
    }

    var $ = layui.$
    var layer = layui.layer
    var divResult = $('#divResult')
    divResult.html('')
    if (uId && amount) {
      $.ajax({
        url: "{:url('index/Test/api',['code' => $code.name])}",
        type: 'POST',
        data: {
          uid: uId,
          amount: amount
        },
        success: function (res) {
          if (res.code == 1) {
            layer.msg(res.msg, { closeBtn: 0, shade: 0.6 })

            if (res.data.type === 'A002' || res.data.type === 'A005' || res.data.type === 'G0071') {
              window.open(res.data.pay_url)
            } else if (res.data.type === 'X0002') {
              window.location.href = res.data.pay_app_url
            } else if (res.data.type === 'X0001') {
              window.location.href = res.data.pay_app_url
            } else {
              if (
                res.data.pay_url &&
                (res.data.pay_url.indexOf('https://') >= 0 ||
                  res.data.pay_url.indexOf('http://') >= 0)
              ) {
                divResult.html(
                  '<img src="' +
                  res.data.pay_url +
                  '" style="width:75%;height:75%"/> <br /><a target="_blank" href="' + res.data.pay_app_url + '">直接打开微信/支付宝</a>'
                )
              } else {
                layer.msg(res.data.msg, { icon: 2, closeBtn: 0, shade: 0.6 })
              }
            }
          } else {
            layer.msg(res.msg, { icon: 2, closeBtn: 0, shade: 0.6 })
          }
        }
      })
    } else {
      layer.msg('请输入商户编号和支付金额。')
    }
  }
</script>
{/block}